package formbeans;

import java.util.ArrayList;
import java.util.List;

import org.mybeans.form.FormBean;

public class MultipleChoiceForm extends FormBean {

	private String question;
	private String dynetmlAttr;
	private String className;
	private String num;
	
	public String getQuestion() {
		return question;
	}
	public String getDynetmlAttr() {
		return dynetmlAttr;
	}
	public String getClassName() {
		return className;
	}
	public String getNum() {
		return num;
	}

	public void setQuestion(String question) {
		this.question = trimAndConvert(question,"<>\"");
	}
	public void setDynetmlAttr(String dynetmlAttr) {
		this.dynetmlAttr = trimAndConvert(dynetmlAttr,"<>\"");
	}
	public void setClassName(String className) {
		this.className = className;
	}
	public void setNum(String num) {
		this.num = trimAndConvert(num,"<>\"");
	}
	
	public List<String> checkMultipleChoiceFormErrors(){
		List<String> errors = new ArrayList<String>();
		
		if(question == null || question.length() == 0){
			errors.add("Please enter a question");
		}
		if(dynetmlAttr == null || dynetmlAttr.length() == 0){
			errors.add("Please enter dynetml attribute identifier");
		}
		
		if(num == null || num.length() == 0) {
			errors.add("Please enter number of choices");
			return errors;
		}
		
		try {
			int i = new Integer(num);
			if (i < 2 || i > 100)
				errors.add("Please enter number between 2 and 100, inclusive");
		} catch (NumberFormatException e) {
			errors.add("Please enter valid number");
		}
		
		return errors;
	}
	
	//Network version of error checking, where num field is disabled
	public List<String> checkMultipleChoiceFormErrorsNetwork() {
		List<String> errors = new ArrayList<String>();
		
		if(question == null || question.length() == 0){
			errors.add("Please enter a question");
		}
		if(dynetmlAttr == null || dynetmlAttr.length() == 0){
			errors.add("Please enter dynetml attribute identifier");
		}
		
		return errors;
	}
}